package com.example.shushiyunsst.widget.verification.new_view

import android.content.Context
import android.view.ViewGroup
import com.example.shushiyunsst.widget.verification.manager.AbstractWindowManager
import com.example.shushiyunsst.widget.verification.manager.IWindowParameter
import com.example.shushiyunsst.widget.verification.view.IBaseView
import com.example.shushiyunsst.widget.verification.view.IVerificationView
import com.example.shushiyunsst.widget.verification.view.VerificationListener
import com.example.shushiyunsst.widget.verification.window.CommonPopWindow
import com.example.shushiyunsst.widget.verification.window.IWindow

class NewVerificationManager(context: Context, parameter: IWindowParameter) :
    AbstractWindowManager(context, parameter), NewVerificationListener {


    private val dragView: INewVerificationView = baseView as INewVerificationView

    private var listener: NewVerificationListener? = null

    override fun makeWindowObj(context: Context?, parameter: IWindowParameter?): IWindow {
        return CommonPopWindow(context)
    }

    override fun makeWindowView(context: Context?, parameter: IWindowParameter?): IBaseView {
        return NewDragVerificationFrameView(context)
    }

    fun show(parent: ViewGroup?, mBean: VerificationViewBean, listener: NewVerificationListener?) {

        this.listener = listener

        dragView.setData(mBean, this)

        show(parent)
    }


    override fun notifyStatusResult(status: Int) {
        when (status) {
            VerificationListener.SUCCESS_STATUS -> {
                listener?.notifyStatusResult(status)
                dismiss()
            }
            VerificationListener.CACEL_STATUS -> {
                dismiss()
            }
        }
    }

    override fun dismiss() {
        super.dismiss()
        dragView.dismiss()
    }
}